/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>Project: smvc2022 - IndexController
 * <p>Powered by webrx On 2022-03-28 09:19:06
 * <p>Created by IntelliJ IDEA  手机号：13014577033
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */

@Controller
public class IndexController {
    @ModelAttribute("name")
    public String name() {
        //freemarker ${name}
        return "张三丰";
    }

    @ModelAttribute("map")
    public Map<String,Object> map(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",108);
        map.put("name","李四七");
        map.put("money",1018.1256f);
        map.put("birth", LocalDate.of(1986,10,20).format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
        map.put("localdate",LocalDate.now());
        map.put("localtime", LocalTime.now());
        map.put("localdatetime", LocalDateTime.now());
        map.put("regtime",new Date());
        return map;
    }

    @RequestMapping
    public String index(Model m) {
        //freemarker
        m.addAttribute("addrs",new String[]{"河南省郑州市","北京市朝阳区","上海市"});
        //m.addAttribute("addrs",new String[]{});
        return "index";
    }

}
